function timeout(ms) {
    return new Promise((resolve, reject) => {
        setTimeout(resolve, ms, 'done');
    });
}

timeout(100).then(value => {
});

let promise = new Promise((resolve, reject) => {
    resolve();
});

promise.then(()=>{
});

function loadimageasync(url) {
    return new Promise((resolve, reject) => {
        const image = new image();
        image.onload = function () {
            resolve(image);
        };
        image.onerror = function () {
            reject(new Error('could not load image at' + url));
        };
        image.src = url;
    });
}

// const promise1 = new Promise((resolve, reject) => {
//     try{
//         throw new Error('test');
//     }catch (e) {
//         reject(e);
//     }
// });
// promise.catch((err)=>{
//     console.log(err);
// });
//
//
// const promise2 = new Promise((resolve, reject) => {
//     reject(new Error('test'));
// });
// promise.catch((err)=>{
//     console.log(err)
// });

function getFoo() {
    return new Promise((resolve, reject) => {
        resolve('foo');
    });
}

const g = function* () {
    try {
        const foo = yield getFoo();
        console.log(foo)
    }catch (e) {
        console.log(e);
    }
};

function run(generator) {
    const it = generator();
    function go(result) {
        if(result.done) return result.value;

        return result.value.then(function (value) {
            return go(it.next(value));
        }, function (err) {
            return go(it.throw(err));
        });
    }
    go(it.next());
}

run(g)